import yfinance as yf
import pandas as pd
import requests

# 设置代理
proxies = {
    "http": "http://your_proxy_address:your_proxy_port",
    "https": "http://your_proxy_address:your_proxy_port"
}

# 定义要查询的股票列表
symbol_list = ['AAPL', 'GOOGL', 'MSFT', 'AMZN', 'META', 'NVDA']

for symbol in symbol_list:
    ticker_data = yf.Ticker(symbol)

    # 使用代理下载数据
    hist_data = ticker_data.history(start="2013-01-01", end="2024-03-07", interval="1d", proxies=proxies)

    # 将DataFrame写入CSV文件
    file_path = f"{symbol}_historical.csv"
    hist_data.to_csv(file_path)

    print(f"Data saved to {file_path}")